<?php
// url 'user/login' with [username, password]
class Twis_Template_TokenParser_Url extends Twig_TokenParser
{
    public function parse(Twig_Token $token)
    {
        $lineno = $token->getLine();
        // $router = $this->parser->getStream()->expect(Twig_Token::STRING_TYPE)->getValue();
        $router = $this->parser->getExpressionParser()->parseExpression();

        // with
        $params = null;
        if ($this->parser->getStream()->test(Twig_Token::NAME_TYPE, 'with')) {
            $this->parser->getStream()->next();
            $params = $this->parser->getExpressionParser()->parseExpression();
        }

        $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);

        return new Twis_Template_Node_Url($router, $params, $lineno, $this->getTag());
    }

    public function getTag()
    {
        return 'url';
    }
}
